<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

    <title>义卖商城支付</title>
    <link href="<?php echo MODULE_URL;?>template/mobile/shop/css/wxpay-index.min.css" rel="stylesheet">
    <style type="text/css">
        #addr_form {width:100%;height:auto;background-color: #fff;margin-bottom:10px;display: none;}
		#addr_form p{line-height:35px;border-bottom:1px solid #eee;padding:0 10px;}
		#addr_form p span{width:23%;display: inline-block;}
		#addr_form input{border:none;width:60%;}
		#addr_form a {text-align:center;cursor:pointer;display:inline-block;width:100%;margin:0 auto 10px;height:34px;border: 1px solid #ddd;background: none;color:#000;}
    </style>
    {template 'include/header'}
    <script type="text/javascript">
        //调用微信JS api 支付
        function jsApiCall() {
            WeixinJSBridge.invoke(
                    'getBrandWCPayRequest',
            <?php echo $jsApiParameters; ?>,
            function (res) {
               // WeixinJSBridge.log(res.err_msg);
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
					location.href = '{php echo $this->createMobileUrl('buy',array('order_id'=>$order_id, 'fund_value'=>$orders['total_price'], 'order_num'=>$out_trade_no))}';
                } else{
                    alert(res.err_code+res.err_desc+res.err_msg);
                }
            });
        }

        function callpay() {
            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            } else {
                jsApiCall();
            }
        }

    </script>
</head>
<body>
<div class="viewport">
    
    <div class="floor">
        <a id="editAddress" href="javascript:;" class="receive-deliver-info  text-style-caption">
            <div class="left-side">
                <i class="icon-ic_location location-icon"></i>
            </div>
            
            <div class="right-side">
                <span class="text-style-caption location-text" id="write_addr">请填写收货地址</span>
                <i class="icon-ic_chevron_right"></i>
            </div>
            <input type="hidden" id="hidProvince">
            <input type="hidden" id="hidCity">
            <input type="hidden" id="hidCounties">
            <input type="hidden" id="hidAddressDetail">
            <input type="hidden" id="hidUserName">
            <input type="hidden" id="hidTel">
            
        </a>
    </div>
    <form id="addr_form">
    	<p><span>收货人 </span><input type="text" name="user_name" id="user_name" placeholder="姓名" /></p>
    	<p><span>手机号码</span><input type="text" name="phone" id="phone" placeholder="11位手机号" /></p>
    	<p><span>详细地址</span><input type="text" name="address" id="address" placeholder="地址信息" /></p>
    	<p><span>邮政编码</span><input type="text" name="bianma" id="bianma" placeholder="邮政编码" /></p>
    	<p style="border-bottom:none"><a id="add_save">保存地址</a></p>
    </form>

    <div class="floor floor-vertical-padding ">
        <a class="goods-image-text-info border-bottom clearfix " href="#">
            <div class="left-box">
                
                <img  class="goods-thumbnail" src="{$_W['attachurl']}{$goods['goods_pic']}" alt=""/>

                <div class="div-goods-detail-info" style="">
                    <span class="goods-name text-style-caption" id="itemName" skuId="01020306002" itemName="{$goods['goods_name']}">{$goods['goods_name']}</span>
                    <span class="goods-material text-style-label">捐助对象: <?php echo $pros['pro_name'];?></span>
                    <span class="goods-count text-style-label" id="itemNum" itemNum="{$buynum}">数量: {$buynum}</span>
                </div>
            </div>
            <div class=" right-price-box text-style-price  ">￥{$goods['goods_price']}</div>
        </a>

        <div class=" floor-horizontal-padding floor-vertical-padding ">
            <span class="float-left text-style-description">订单总金额</span>
            <span class="float-right text-style-status " id="totalAmount" tag="<?php echo floatval($goods['goods_price']*$buynum);?>">￥<?php echo $goods['goods_price']*$buynum?></span>
        </div>
        <div class=" floor-horizontal-padding floor-vertical-padding ">
            <span class="float-left text-style-description">您购买的资金将会作为“<i style="color:#000">{$pros['pro_name']}</i>”项目的公益基金</span>
        </div>

    </div>

    <div class="">
        <button id="payByWeChat" href="javascript:;" class="btn-dark btn-buy-now btn-pay-wechat" tag1=>
            <i class="icon-btn_pay_with_wechat_wallet wechat-icon"></i>微信支付
        </button>
        
    </div>

    <div class="sku_tip" id="skuNotice" style="display:none">
        <span id="skuTitle2"></span>
    </div>
    
    <div class="floor service-in-wechat" >
    <div class="service-title-box">
        <i class="icon-ic_call_center"></i>
        <span class="text-style-caption title">义卖商城微信客服 </span>
    </div>

    <div class="erweima-box" >
        <img src="{$_W['attachurl']}{$mall_set['code_pic']}" class="full-image erweima-img" alt="二维码"/>
        <span class="">长按识别二维码直接呼叫客服</span>
    </div>

</div>
</div>
<script type="text/javascript" src="<?php echo MODULE_URL;?>template/mobile/js/jquery-1.11.1.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="<?php echo MODULE_URL;?>template/mobile/shop/js/fastclick.min.js" charset="UTF-8"></script>
<script language="javascript" src="<?php echo MODULE_URL;?>/template/mobile/shop/js/tocca.min.js"></script>
<script data-main="<?php echo MODULE_URL;?>template/mobile/shop/js/pay_confirm_v201601131639.min" src="<?php echo MODULE_URL;?>template/mobile/shop/js/require.js"></script>
<script type="text/javascript" src="<?php echo MODULE_URL;?>template/mobile/shop/js/stats.js" charset="UTF-8"></script>
<script type="text/javascript">
	$(function() {
	    FastClick.attach(document.body);
	});
	$("#editAddress").click(function(){ 
		$("#addr_form").css("display","block");
	});
	$("#add_save").click(function(){ 
		var user_name = $("#user_name").val();
        var phone = $("#phone").val();   
        var address = $("#address").val();
        var bianma = $("#bianma").val();
        if(user_name=="") {
            alert( "请输入姓名!");
            return ;
        }

        if (address=="") {
            alert("请输入详细地址");
            return ;
        }
        if (bianma=="") {
            alert("请输入邮政编码");
            return ;
        }
        
        if (!/^1\d{10}$/.test(phone)) {//
            alert("请输入正确的电话号码");
            return ;
        }
        $(".right-side").html("<span class='text-style-caption location-text' id='address_last'>送至："+user_name+" "+phone+" "+address+" "+bianma+"</span>");
        $("#addr_form").css("display","none");
        var address = user_name+" "+phone+" "+address+" "+bianma;
        $.post("<?php echo $this->createMobileUrl('add_address')?>",{order_id:{$order_id},address:address},
		  function(data){},
		  "text");
		
	});
	$("#payByWeChat").click(function(){ 
		if($(".right-side").html().indexOf("请填写收货地址")<0){ 
			callpay();		
		} else { 
			alert("请填写收货地址");}
	});

</script>
<div style="height: 80px"></div>


</body>
</html>
